package com.master.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.sina.sae.util.SaeUserInfo;

public class DBHelper {
	private static final String R_URL = "jdbc:mysql://r.rdc.sae.sina.com.cn:3307/app_ericxu";
	private static final String W_URL = "jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_ericxu";
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	
	public static Connection getReadConnection() {
		String userName = SaeUserInfo.getAccessKey();
		String password = SaeUserInfo.getSecretKey();
		try {
			Class.forName(DRIVER).newInstance();
			return DriverManager.getConnection(R_URL, userName, password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static Connection getWriteConnection() {
		String userName = SaeUserInfo.getAccessKey();
		String password = SaeUserInfo.getSecretKey();
		try {
			Class.forName(DRIVER).newInstance();
			return DriverManager.getConnection(W_URL, userName, password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
